package com.transaction.manage.service.dayEnd;

import com.transaction.common.util.ConstUtil;
import com.transaction.common.util.JsonUtil;
import com.transaction.common.util.ParamsUtil;
import com.transaction.manage.localMapper.*;
import com.transaction.manage.model.dto.ChannelInfo;
import com.transaction.manage.model.dto.FundInfo;
import com.transaction.manage.model.dto.Market;
import com.transaction.manage.model.vo.HandleVo;
import com.transaction.manage.model.vo.MarketVo;
import com.transaction.manage.service.BusinessHandleService;
import com.transaction.manage.util.BuildFileUtil;
import com.transaction.manage.util.SpringUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class MarketHandle {

    private static Logger LOGGER = LoggerFactory.getLogger(MarketHandle.class);


    /**
     * 1、把已到期并且超过到期日X天的产品状态更新成不可用,默认30天
     * @param channelInfo 渠道信息
     * @param handleDate 处理日期
     * @param logCode 日志code
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public HandleVo stopExpireFund(ChannelInfo channelInfo, String handleDate, String logCode,Integer stepCode){

        if(channelInfo == null || StringUtils.isEmpty(handleDate) || StringUtils.isEmpty(logCode) || stepCode == null){
            return HandleVo.error("渠道信息/处理日期/日志编码//处理步骤编码为空。");
        }

        String channelCode = channelInfo.getChannelCode();

        if(StringUtils.isEmpty(channelCode)){
            return HandleVo.error("渠道编码为空。");
        }

        try{
            LOGGER.info("第【{}】步开始处理。。。",stepCode);
            //把到期超过多少天的产品更新成停用
            FundInfoMapper fundInfoMapper = SpringUtil.getBean(FundInfoMapper.class);
            int stopCount = fundInfoMapper.stopExpireFund(channelCode,handleDate);
            LOGGER.info("渠道:【{}】,处理日期:【{}】,停用产品【{}】个",channelCode,handleDate,stopCount);
            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            return HandleVo.ok();

        }catch(Exception e){
            String errorMsg = ParamsUtil.getErrorMsg(e);
            //异步插入流程日志详情表
            BusinessHandleService businessHandleService = SpringUtil.getBean(BusinessHandleService.class);
            businessHandleService.asyncInsertLogDetail(logCode,errorMsg);
            LOGGER.error("渠道:【{}】,处理日期:【{}】,=>{MarketHandle.stopExpireFund}<= 发生异常 => 【{}】 ,请处理。",channelCode,handleDate,errorMsg);
            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            return HandleVo.error("未知异常,请【点击】查看详情。");
        }
    }


    /**
     * 2、查询渠道产品数据,组装成行情数据,基础默认值入库
     * @param channelInfo 渠道信息
     * @param handleDate 处理日期
     * @param logCode 日志code
     * @param stepCode 步骤编号
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public HandleVo saveMarketData(ChannelInfo channelInfo, String handleDate, String logCode,Integer stepCode){
        /**
         * 1、查询有效的可用的产品信息
         * 2、组装成可插入行情表的数据格式,部分数据先给默认值，后期更新
         * 3、插入行情表
         */

        if(channelInfo == null || StringUtils.isEmpty(handleDate) || StringUtils.isEmpty(logCode) || stepCode == null){
            return HandleVo.error("渠道信息/处理日期/日志编码/处理步骤编码为空。");
        }

        String channelCode = channelInfo.getChannelCode();

        if(StringUtils.isEmpty(channelCode)){
            return HandleVo.error("渠道编码为空。");
        }

        try{

            LOGGER.info("第【{}】步开始处理。。。",stepCode);
            MarketMapper marketMapper = SpringUtil.getBean(MarketMapper.class);
            //删除行情数据
            marketMapper.deleteMarketByChannelAndHandleDate(channelCode,handleDate);

            FundInfoMapper fundInfoMapper = SpringUtil.getBean(FundInfoMapper.class);
            List<FundInfo> fundInfoList = fundInfoMapper.selectValidFundInfo(channelCode);

            if(CollectionUtils.isNotEmpty(fundInfoList)){

                //转换
                List<Market> marketList = buildToSaveMarketData(fundInfoList,handleDate);

                if(CollectionUtils.isNotEmpty(marketList)) {
                    //插入
                    marketMapper.insertMarketList(marketList);
                }
            }

            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            return HandleVo.ok();

        }catch(Exception e){
            String errorMsg = ParamsUtil.getErrorMsg(e);
            //异步插入流程日志详情表
            BusinessHandleService businessHandleService = SpringUtil.getBean(BusinessHandleService.class);
            businessHandleService.asyncInsertLogDetail(logCode,errorMsg);
            LOGGER.error("渠道:【{}】,处理日期:【{}】,=>{MarketHandle.saveMarketData}<= 发生异常 => 【{}】 ,请处理。",channelCode,handleDate,errorMsg);
            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            return HandleVo.error("未知异常,请【点击】查看详情。");
        }
    }

    /**
     * 3、通过产品交易日,产品类型交易日，结转日等信息，把给到的默认状态更新
     * @param channelInfo 渠道信息
     * @param handleDate 处理日期
     * @param logCode 日志code
     * @param stepCode 步骤编号
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public HandleVo calculateMarketStatus (ChannelInfo channelInfo, String handleDate, String logCode,Integer stepCode){

        /**
         * 1、查询上一步处理完的行情数据，以及每个产品的所对应的产品类型，产品开放日等信息
         * 2、在原有的状态基础上根据以上条件判断，重新赋值行情状态
         * 3、更新渠道产品的新的行情状态
         */
        if(channelInfo == null || StringUtils.isEmpty(handleDate) || StringUtils.isEmpty(logCode) || stepCode == null){
            return HandleVo.error("渠道信息/处理日期/日志编码/处理步骤编码为空.");
        }

        String channelCode = channelInfo.getChannelCode();

        if(StringUtils.isEmpty(channelCode)){
            return HandleVo.error("渠道编码为空。");
        }

        MarketMapper marketMapper = SpringUtil.getBean(MarketMapper.class);
        BusinessHandleService businessHandleService = SpringUtil.getBean(BusinessHandleService.class);
        try {

            LOGGER.info("第【{}】步开始处理。。。", stepCode);

            List<MarketVo> list = marketMapper.selectMarketInfoList(channelCode,handleDate);

            if(CollectionUtils.isNotEmpty(list)) {
                reCalculateStatus(channelInfo.getMarketCode(),handleDate,list);
                marketMapper.updateMarketFundStatus(list);
            }

            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            businessHandleService.asyncUpdateFlowStep("market",",stepCode_" + stepCode + ":success",channelCode,handleDate);
            return HandleVo.ok();

        }catch(Exception e){
            String errorMsg = ParamsUtil.getErrorMsg(e);
            //异步插入流程日志详情表
            businessHandleService.asyncInsertLogDetail(logCode,errorMsg);
            businessHandleService.asyncUpdateFlowStep("market",",stepCode_" + stepCode + ":failed",channelCode,handleDate);
            LOGGER.error("渠道:【{}】,处理日期:【{}】,=>{MarketHandle.calculateMarketStatus}<= 发生异常 => 【{}】 ,请处理。",channelCode,handleDate,errorMsg);
            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            return HandleVo.error("未知异常,请【点击】查看详情。");
        }
    }


    /**
     * 4、通过关联的TA产品信息，查询出对应的净值，净值日期，累计净值，七日年化，万份收益等信息，把给到的默认值更新
     * @param channelInfo 渠道信息
     * @param handleDate 处理日期
     * @param logCode 日志code
     * @param stepCode 步骤编号
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public HandleVo getFundNetValue (ChannelInfo channelInfo, String handleDate, String logCode,Integer stepCode){
        /**
         * 1、校验所有的上一步行情产品是否都有对应的TA产品
         * 2、查询上一步处理完的行情数据，以及每个产品关联的TA产品（多个任取一个），通过TA产品查询净值和万份收益，七日年化
         * 3、更新渠道产品的新的净值数据等
         */
        if(channelInfo == null || StringUtils.isEmpty(handleDate) || StringUtils.isEmpty(logCode) || stepCode == null){
            return HandleVo.error("渠道信息/处理日期/日志编码/处理步骤编码为空.");
        }

        String channelCode = channelInfo.getChannelCode();

        if(StringUtils.isEmpty(channelCode)){
            return HandleVo.error("渠道编码为空。");
        }

        BusinessHandleService businessHandleService = SpringUtil.getBean(BusinessHandleService.class);

        try {
            LOGGER.info("第【{}】步开始处理。。。", stepCode);

            HandleDataCheck handleDataCheck = SpringUtil.getBean(HandleDataCheck.class);
            List<LinkedHashMap<String,Object>> notMappingTaFund = handleDataCheck.checkMarketFundNotMappingTaFund(channelCode,handleDate);
            if(CollectionUtils.isNotEmpty(notMappingTaFund)){
                //异步插入流程日志详情表
                businessHandleService.asyncUpdateFlowStep("market",",stepCode_" + stepCode + ":failed",channelCode,handleDate);
                businessHandleService.asyncInsertLogDetail(logCode, JsonUtil.getListMapToLineFeedJson(notMappingTaFund));
                return HandleVo.error("有产品没有关联TA产品,请【点击】查看详情。");
            }

            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            businessHandleService.asyncUpdateFlowStep("market",",stepCode_" + stepCode + ":success",channelCode,handleDate);
            return HandleVo.ok();

        }catch(Exception e){
            String errorMsg = ParamsUtil.getErrorMsg(e);
            //异步插入流程日志详情表
            businessHandleService.asyncInsertLogDetail(logCode,errorMsg);
            businessHandleService.asyncUpdateFlowStep("market",",stepCode_" + stepCode + ":failed",channelCode,handleDate);
            LOGGER.error("渠道:【{}】,处理日期:【{}】,=>{MarketHandle.getFundNetValue}<= 发生异常 => 【{}】 ,请处理。",channelCode,handleDate,errorMsg);
            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            return HandleVo.error("未知异常,请【点击】查看详情。");
        }
    }

    /**
     * 5、生成文件
     * @param channelInfo 渠道信息
     * @param handleDate 处理日期
     * @param logCode 日志code
     * @param stepCode 步骤编号
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public HandleVo generateFile(ChannelInfo channelInfo, String handleDate, String logCode,Integer stepCode){

        /**
         * 1、查询当前处理日期，当前渠道的行情数据
         * 2、组装文件内容
         * 3、写出其对应的索引文件
         * 4、写出正式文件
         */
        if(channelInfo == null || StringUtils.isEmpty(handleDate) || StringUtils.isEmpty(logCode) || stepCode == null){
            return HandleVo.error("渠道信息/处理日期/日志编码/处理步骤编码为空.");
        }

        String channelCode = channelInfo.getChannelCode();
        String versionCode = channelInfo.getVersionCode();

        if(StringUtils.isEmpty(channelCode)){
            return HandleVo.error("渠道编码为空。");
        }

        BusinessHandleService businessHandleService = SpringUtil.getBean(BusinessHandleService.class);

        try {
            LOGGER.info("第【{}】步开始处理。。。", stepCode);

            InterfaceFieldMapper interfaceFieldMapper = SpringUtil.getBean(InterfaceFieldMapper.class);
            //查询对应的接口字段
            List<Map<String,Object>> interfaceList = interfaceFieldMapper.selectInterfaceForMap(ConstUtil.FILE_TYPE_07 + "000" + versionCode);
            if(CollectionUtils.isEmpty(interfaceList)){
                businessHandleService.asyncUpdateFlowStep("market",",stepCode_" + stepCode + ":failed",channelCode,handleDate);
                return HandleVo.error("生成文件字段接口为空，请联系管理员配置。");
            }

            //获得数据行
            MarketMapper marketMapper = SpringUtil.getBean(MarketMapper.class);
            List<Map<String, Object>> marketList = marketMapper.selectMarketWriteFileData(channelCode,handleDate);

            BuildFileUtil.generateFile("07",handleDate.replace("-",""),channelInfo,marketList,interfaceList);

            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            businessHandleService.asyncUpdateFlowStep("market",",stepCode_" + stepCode + ":success",channelCode,handleDate);
            return HandleVo.ok();

        }catch(Exception e){
            String errorMsg = ParamsUtil.getErrorMsg(e);
            //异步插入流程日志详情表
            businessHandleService.asyncInsertLogDetail(logCode,errorMsg);
            businessHandleService.asyncUpdateFlowStep("market",",stepCode_" + stepCode + ":failed",channelCode,handleDate);
            LOGGER.error("渠道:【{}】,处理日期:【{}】,=>{MarketHandle.generateFile}<= 发生异常 => 【{}】 ,请处理。",channelCode,handleDate,errorMsg);
            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            return HandleVo.error("未知异常,请【点击】查看详情。");
        }
    }


    /**
     * 6、发送文件
     * @param channelInfo 渠道信息
     * @param handleDate 处理日期
     * @param logCode 日志编码
     * @param stepCode 处理步骤编号
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public HandleVo sendFile(ChannelInfo channelInfo, String handleDate, String logCode,Integer stepCode){
        if(channelInfo == null || StringUtils.isEmpty(handleDate) || StringUtils.isEmpty(logCode) || stepCode == null){
            return HandleVo.error("渠道信息/处理日期/日志编码/处理步骤编码为空.");
        }

        String channelCode = channelInfo.getChannelCode();

        if(StringUtils.isEmpty(channelCode)){
            return HandleVo.error("渠道编码为空。");
        }

        BusinessHandleService businessHandleService = SpringUtil.getBean(BusinessHandleService.class);

        try {
            LOGGER.info("第【{}】步开始处理。。。", stepCode);


            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            businessHandleService.asyncUpdateFlowStep("market",",stepCode_" + stepCode + ":success",channelCode,handleDate);
            return HandleVo.ok();

        }catch(Exception e){
            String errorMsg = ParamsUtil.getErrorMsg(e);
            //异步插入流程日志详情表
            businessHandleService.asyncInsertLogDetail(logCode,errorMsg);
            businessHandleService.asyncUpdateFlowStep("market",",stepCode_" + stepCode + ":failed",channelCode,handleDate);
            LOGGER.error("渠道:【{}】,处理日期:【{}】,=>{MarketHandle.sendFile}<= 发生异常 => 【{}】 ,请处理。",channelCode,handleDate,errorMsg);
            LOGGER.info("第【{}】步处理结束。。。",stepCode);
            return HandleVo.error("未知异常,请【点击】查看详情。");
        }
    }
    /**
     * 根据产品类型，开放日信息重新计算行情状态
     * @param marketCode 所属市场编码
     * @param handleDate 处理日期
     * @param list 行情信息集合
     */
    private void reCalculateStatus(String marketCode,String handleDate, List<MarketVo> list) {
        //丰利结转日每月15  红七结转日每季度15日  非工作日顺延
        HandleDataCheck handleDataCheck = SpringUtil.getBean(HandleDataCheck.class);
        //是否丰利结转日
        boolean isFundType1CarryOverDay = handleDataCheck.checkDayIsFundType1CarryOver(marketCode,handleDate);
        //是否红七结转日
        boolean isFundType2CarryOverDay = handleDataCheck.checkDayIsFundType2CarryOver(marketCode,handleDate);

        MarketDateMapper marketDateMapper = SpringUtil.getBean(MarketDateMapper.class);
        Integer week = marketDateMapper.selectHandleDateWeek(handleDate);

        /**
         * -----fundStatus为4-停止申购赎回（运作期），才需要再次判断，其他状态为根据4个日期给到正确状态---
         * 1、丰利产品始终是0-可申购赎回，结转日6-停止赎回
         * 2、红七特殊，周一5-停止申购，周二6-停止赎回
         * 3、其他产品根据设置的开放净值类判断
         */
        for (MarketVo vo : list) {
            String fundStatus = vo.getFundStatus();
            String fundType = vo.getFundType();

            if(!"4".equals(fundStatus)){
                continue;
            }

            if("1".equals(fundType)){
                fundStatus = "0";
                if(isFundType1CarryOverDay){
                    fundStatus = "6";
                }
            }else if("2".equals(fundType)){
                if("1".equals(week)){
                    fundStatus = "5";
                    if(isFundType2CarryOverDay){
                        fundStatus = "4";
                    }
                }else if("2".equals(week)){
                    fundStatus = "6";
                }
            }else{
                Integer isAllow022 = vo.getIsAllow022();
                Integer isAllow024 = vo.getIsALLOW024();

                if(isAllow022 > 0){
                    fundStatus = "6";
                }
                if(isAllow024 > 0){
                    fundStatus = "5";
                }
                if(isAllow022 > 0 && isAllow024 > 0){
                    fundStatus = "0";
                }
            }
            vo.setFundStatus(fundStatus);
        }
    }

    /**
     * 组装行情数据
     * @param fundInfoList 行情数据集合
     * @param handleDate 处理日期
     * @return
     */
    private List<Market> buildToSaveMarketData(List<FundInfo> fundInfoList, String handleDate) {

        List<Market> retList = new ArrayList<>();

        fundInfoList.forEach(v->{
            Market market = new Market();

            market.setChannelCode(v.getChannelCode());
            market.setHandleDate(handleDate);

            //必填项默认值
            market.setFundName(v.getFundName());
            market.setTotalFundVol(new BigDecimal(100000000));
            market.setFundCode(v.getFundCode());
            //根据4个日期判断基金的状态
            String status = judgeMarketStatusBy4Date(v,handleDate);
            market.setFundStatus(status);
            //净值和累计净值给1
            market.setNav(new BigDecimal(1));//TODO
            market.setUpdateDate(handleDate.replace("-",""));//TODO
            market.setNetValueType("0");
            market.setAccumulativeNav(new BigDecimal(1));//TODO
            market.setConvertStatus("0");//TODO
            market.setPeriodicStatus("0");
            market.setTransferAgencyStatus("0");
            market.setFundSize(new BigDecimal(100000000));//TODO
            market.setCurrencyType("156");
            market.setAnnouncFlag("0");
            market.setDefDividendMethod("1");

            market.setInstAppSubsAmnt(v.getInstAppendMinAmount());
            market.setInstAppSubsVol(new BigDecimal(0));
            market.setMinAmountByInst(v.getInstFirstMinAmount());
            market.setMinVolByInst(new BigDecimal(0));
//            market.setCustodianCode("");
//            market.setAmountOfPeriodicSubs(new BigDecimal(0));
//            market.setDateOfPeriodicSubs("");
            market.setMaxRedemptionVol(new BigDecimal(1000000));
            market.setMinAccountBalance(v.getInstBookMinVol());

            market.setIpoStartDate(v.getIpoBeginDate().replace("-",""));
            market.setIpoEndDate(v.getIpoEndDate().replace("-",""));

//            market.setFundManagerCode("");
            market.setIndiAppSubsVol(new BigDecimal(0));
            market.setIndiAppSubsAmount(v.getIndiAppendMinAmount());
            market.setMinSubsVolByIndi(new BigDecimal(0));
            market.setMinSubsAmountByIndi(v.getIndiFirstMinAmount());
//            market.setRegistrarCode("");
//            market.setFundSponsor("");
            market.setTradingPrice(new BigDecimal(0));
            market.setFaceValue(new BigDecimal(0));
//            market.setDividentDate("");
//            market.setRegistrationDate("");
//            market.setXrDate("");
            market.setMaxSubsVolByIndi(new BigDecimal(100000000));
            market.setMaxSubsAmountByIndi(v.getIndiFirstMaxAmount());
            market.setMaxSubsVolByInst(new BigDecimal(100000000));
            market.setMaxSubsAmountByInst(v.getInstFirstMaxAmount());
            market.setUnitSubsVolByIndi(new BigDecimal(1));
            market.setUnitSubsAmountByIndi(v.getIndiFirstRangeAmount());
            market.setUnitSubsVolByInst(new BigDecimal(1));
            market.setUnitSubsAmountByInst(v.getInstFirstRangeAmount());
            market.setMinBidsAmountByIndi(v.getIndiFirstMinAmount());
            market.setMinBidsAmountByInst(v.getInstFirstMinAmount());
            market.setMinAppBidsAmountByIndi(v.getIndiAppendMinAmount());
            market.setMinAppBidsAmountByInst(v.getInstAppendMinAmount());
            market.setMinRedemptionVol(v.getIndiRedeemMinVol());
            market.setMinInterconvertVol(new BigDecimal(1));
            market.setIssueTypeByIndi("3");
            market.setIssueTypeByInst("3");
            market.setSubsType("0");
            market.setCollectFeeType("0");
//            market.setNextTradeDate("");
            market.setValueLine(new BigDecimal(1));
            market.setTotalDivident(new BigDecimal(1));
            //货币基金七日年化和万份收益
            market.setFundIncome(new BigDecimal(0.5));//TODO
            market.setFundIncomeFlag("0");//TODO
            market.setYield(new BigDecimal(0.5));//TODO
            market.setYieldFlag("0");//TODO
            market.setGuaranteedNav(new BigDecimal(1));//TODO
            market.setFundYearIncomeRate(new BigDecimal(0.5));//TODO
            market.setFundYearIncomeRateFlag("0");//TODO
            market.setIndiMaxPurchase(v.getIndiFirstMaxAmount());
            market.setInstMaxPurchase(v.getInstFirstMaxAmount());
            market.setIndiDayMaxSumBuy(new BigDecimal(1000000000));
            market.setInstDayMaxSumBuy(new BigDecimal(1000000000));
            market.setIndiDayMaxSumRedeem(new BigDecimal(1000000000));
            market.setInstDayMaxSumRedeem(new BigDecimal(1000000000));
            market.setIndiMaxRedeem(new BigDecimal(1000000000));
            market.setInstMaxRedeem(new BigDecimal(1000000000));
            market.setFundDayIncomeFlag("0");//TODO
            market.setFundDayIncome(new BigDecimal(1));//TODO
            market.setAllowBreachRedempt("0");
//            market.setFundType("");
//            market.setFundTypeName("");
//            market.setRegistrarName("");
//            market.setFundManagerName("");
//            market.setFundServerTel("");
//            market.setFundInternetAddress("");
//            market.setMainFundCode("");
//            market.setSideBagFlag("0");

            //插入步骤编号
            market.setFlowStep("stepCode_1:success");

            retList.add(market);
        });

        return retList;
    }

    /**
     * 通过产品的4个日期[募集开始日，募集结束日，成立日，到期日]判断行情的状态
     * @param v 产品信息
     * @param handleDate 处理日期
     */
    private String judgeMarketStatusBy4Date(FundInfo v,String handleDate) {
        String ipoBeginDate = v.getIpoBeginDate();
        String ipoEndDate = v.getIpoEndDate();
        String setUpDate = v.getSetUpDate();
        String maturityDate = v.getMaturityDate();

        /***
         * 1、当前日期比募集开始日小,基金状态为：9-基金封闭
         * 2、当前日期在募集开始到募集结束之间的，基金状态为：1-发行
         * 3、当前日期大于募集结束日小于成立日，基金状态为：9-基金封闭
         * 4、当前日期大于等于成立日，小于到期日，基金状态为：4-不可申购赎回
         * 5、当前日期大于等于到期日，基金状态为：8-基金终止
         */

        String status = "";

        if(handleDate.compareTo(ipoBeginDate) < 0){
            status = "9";
        }

        if(handleDate.compareTo(ipoBeginDate) >= 0 && handleDate.compareTo(ipoEndDate) <= 0 ){
            status = "1";
        }

        if(handleDate.compareTo(ipoEndDate) > 0 && handleDate.compareTo(setUpDate) < 0 ){
            status = "9";
        }

        if(handleDate.compareTo(setUpDate) >= 0 && handleDate.compareTo(maturityDate) < 0 ){
            status = "4";
        }
        if(handleDate.compareTo(maturityDate) >= 0){
            status = "8";
        }

        return status;
    }


}
